<template>
  <el-dialog
    title="添加"
    :visible.sync="addVisible"
    :before-close="close"
    :close-on-click-modal="false"
    width="30%"
    top="5vh"
  >
    <el-form ref="form" :model="form" label-width="100px">
      <el-form-item label="key" prop="key" required>
        <el-input
          v-model="form.key"
          placeholder="唯一标识"
          style="width: 100%"
        ></el-input>
      </el-form-item>
      <el-form-item label="源地址" prop="source" required>
        <el-input
          v-model="form.source"
          placeholder="rtsp, rtmp, 视频文件地址等"
          style="width: 100%"
        ></el-input>
      </el-form-item>
      <el-form-item label="分辨率" prop="resolution">
        <el-input
          v-model="form.resolution"
          placeholder="例如：640x480"
          style="width: 100%"
        ></el-input>
      </el-form-item>
      <el-form-item label="懒加载" prop="lazy">
        <el-select v-model="form.lazy" style="width: 100%">
          <el-option label="是" value="true"></el-option>
          <el-option label="否" value="false"></el-option>
        </el-select>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="close">取消</el-button>
      <el-button type="primary" @click="save">添加</el-button>
    </div>
  </el-dialog>
</template>

<script>
export default {
  data() {
    return {
      form: {
        key: "",
        source: "",
        resolution: "",
        lazy: "true",
      },
    };
  },
  props: {
    addVisible: {
      type: Boolean,
      default: false,
    },
  },
  methods: {
    close() {
      this.form = {
        key: "",
        source: "",
        resolution: "",
        lazy: "true",
      };
      this.$emit("hideAdd");
      this.$emit("search");
    },
    save() {
      if (this.form.key == "") {
        this.$message.warning("唯一标识必填");
        return;
      }
      if (this.form.source == "") {
        this.$message.warning("源地址必填");
        return;
      }
      this.$axios.post("/streamer/add", this.form).then((res) => {
        if (res.data.code != 0) {
          this.$message.error(res.data.msg);
        } else {
          this.close();
          this.$emit("search");
        }
      });
    },
  },
  mounted() {},
};
</script>

<style>
</style>